<!--
 * @Description: 
 * @Autor: 孙婧雯
 * @Date: 2021-07-04 14:03:11
 * @LastEditors: 孙婧雯
 * @LastEditTime: 2021-07-04 14:14:13
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #div1 {
      width: 300px;
      height: 300px;
      background: red;
    }

    #div2 {
      width: 200px;
      height: 200px;
      background: green;
    }

    #div3 {
      width: 100px;
      height: 100px;
      background: blue;
    }
  </style>
</head>

<body>
  <div id="div1">div1
    <div id="div2">div2
      <div id="div3">div3</div>
    </div>
  </div>
  <script>
    var oDiv1 = document.getElementById('div1')
    var oDiv2 = document.getElementById('div2')
    var oDiv3 = document.getElementById('div3')

    // 事件冒泡 子元素的事件触发冒泡到父元素的身上
    // oDiv1.onclick = function () {
    //   console.log('div1');
    // }
    // oDiv2.onclick = function () {
    //   console.log('div2');
    // }
    // oDiv3.onclick = function (e) {
    //   e.stopPropagation();
    //   console.log('div3');
    // }

    // false => 事件冒泡 ； true => 事件捕获
    oDiv1.addEventListener('click', function () {
      console.log('div1');
    }, true)
    oDiv2.addEventListener('click', function () {
      console.log('div2');
    }, true)
    oDiv3.addEventListener('click', function () {
      console.log('div3');
    }, true)
  </script>
</body>

</html>